package com.me.modules.sys.controller;

import java.util.ArrayList;
import java.util.List;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.me.modules.sys.entity.TimetblWorktimeEntity;
import com.me.modules.sys.service.TimetblWorktimeService;
import com.me.modules.common.utils.Result;

import javax.servlet.http.HttpServletRequest;


/**
 * 系统每日工作时间表
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-08 16:56:48
 */
@Controller
@RequestMapping("/sys/timetblworktime")
public class TimetblWorktimeController extends BaseController{
	@Autowired
	private TimetblWorktimeService timetblWorktimeService;
	/**
	 * 列表
	 */
	@RequestMapping(value = "list",method = RequestMethod.GET)
	//@RequiresPermissions("timetblworkdate:list")
	@SysLog("查询工作时间模板")
	public String  list(TimetblWorktimeEntity timetblWorktime, Model model , HttpServletRequest request){
		//Query query = new Query(params);
		List<TimetblWorktimeEntity> timetblWorktimeList =new ArrayList<TimetblWorktimeEntity>();
		if(timetblWorktime.getTmpId()!=null){
			timetblWorktimeList = timetblWorktimeService.queryListByBean(timetblWorktime);
		}//List<TimetblWorkdateEntity> timetblWorkdateList = timetblWorkdateService.queryList(query);
		model.addAttribute("timetblWorktimeList",timetblWorktimeList);
		model.addAttribute("timetblWorktime",timetblWorktime);
		return "sys/timetblworktime/list";
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info")
	//@RequiresPermissions("timetblinfo:info")
	@SysLog("查询工作时间列表")
	public String info( Model model,Long id, HttpServletRequest request){
		TimetblWorktimeEntity timetblWorktime = timetblWorktimeService.queryObject(id);
		model.addAttribute("timetblWorktime",timetblWorktime);
		return "sys/timetblworktime/edit";
	}



	@RequestMapping(value = "save",method = RequestMethod.POST)
	//@RequiresPermissions("timetblinfo:save")
	@ResponseBody
	public Result save(TimetblWorktimeEntity timetblWorktime){
		if (timetblWorktime.getFriEndtime()==""||timetblWorktime.getFriStarttime()==""){
			timetblWorktime.setFriEndtime("");
			timetblWorktime.setFriStarttime("");
		}
		if (timetblWorktime.getMonEndtime()==""||timetblWorktime.getMonStarttime()==""){
			timetblWorktime.setMonEndtime("");
			timetblWorktime.setMonStarttime("");
		}
		if (timetblWorktime.getSatEndtime()==""||timetblWorktime.getSatStarttime()==""){
			timetblWorktime.setSatEndtime("");
			timetblWorktime.setSatStarttime("");
		}
		if (timetblWorktime.getSunEndtime()==""||timetblWorktime.getSunStarttime()==""){
			timetblWorktime.setSunEndtime("");
			timetblWorktime.setSunStarttime("");
		}
		if (timetblWorktime.getThursEndtime()==""||timetblWorktime.getThursStarttime()==""){
			timetblWorktime.setThursEndtime("");
			timetblWorktime.setThursStarttime("");
		}
		if (timetblWorktime.getTuesStarttime()==""||timetblWorktime.getTuesEndtime()==""){
			timetblWorktime.setTuesEndtime("");
			timetblWorktime.setTuesStarttime("");
		}
		if (timetblWorktime.getWenStarttime()==""||timetblWorktime.getWenEndtime()==""){
			timetblWorktime.setWenEndtime("");
			timetblWorktime.setWenStarttime("");
		}
		if(timetblWorktime.getId()==null) {
			timetblWorktimeService.save(timetblWorktime);
		}else {
			timetblWorktimeService.update(timetblWorktime);
		}
		return Result.ok().put("timetblWorktime",timetblWorktime);
	}



	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("TimetblWorktime:update")
	public Result update(@RequestBody TimetblWorktimeEntity timetblWorktime){
		timetblWorktimeService.update(timetblWorktime);

		return Result.ok();
	}


	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Result edit(Long id){
		if(timetblWorktimeService.delete(id)<1){
			return Result.error("删除工作时间失败");
		}
		return Result.ok("删除工作时间成功");
	}
}
